/**
 * Copyright (C) 2003 DFKI GmbH. All rights reserved.
 */
package marytts.language.fr;

import marytts.util.dom.DomUtils;

import org.custommonkey.xmlunit.*;
import org.testng.Assert;
import org.testng.annotations.*;
import org.w3c.dom.Document;

/**
 * @author Tristan Hamilton
 */
public class PreprocessTest {

    private static Preprocess module;

    @BeforeSuite
    public static void setUpBeforeClass() {
        module = new Preprocess();
    }

    @DataProvider(name = "DocData")
    private Object[][] numberExpansionDocData() {
        return new Object[][]{{"1", "un"},
                {"2", "deux"},
                {"3", "trois"},
                {"4", "quatre"},
                {"42", "quarante-deux"},
                {"1er", "premier"},
                {"1re", "première"},
                {"2e", "deuxième"},
                {"3e", "troisième"},
                {"4e", "quatrième"}};
    }

    @DataProvider(name = "NumExpandData")
    private Object[][] numberExpansionDocDataCardinal() {
        return new Object[][]{{"1", "un"},
                {"2", "deux"},
                {"3", "trois"},
                {"4", "quatre"},
                {"42", "quarante-deux"}};
    }

    @DataProvider(name = "OrdinalExpandData")
    private Object[][] numberExpansionDocDataOrdinal() {
        return new Object[][]{{"2", "deuxième"},
                {"3", "troisième"},
                {"4", "quatrième"}};
    }

    @Test(dataProvider = "DocData")
    public void testSpellout(String tokenised, String expected) throws Exception {
        Document tokenisedDoc;
        Document expectedDoc;
        String tokens = "<maryxml xmlns=\"http://mary.dfki.de/2002/MaryXML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"0.5\" xml:lang=\"fr\"><p><s><t>"
                + tokenised + "</t></s></p></maryxml>";
        tokenisedDoc = DomUtils.parseDocument(tokens);
        String words = "<maryxml xmlns=\"http://mary.dfki.de/2002/MaryXML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"0.5\" xml:lang=\"fr\"><p><s><mtu orig=\""
                + tokenised + "\"><t>" + expected + "</t></mtu></s></p></maryxml>";
        expectedDoc = DomUtils.parseDocument(words);
        module.checkForNumbers(tokenisedDoc);
        Diff diff = XMLUnit.compareXML(expectedDoc, tokenisedDoc);
        Assert.assertTrue(diff.identical());
    }

    @Test(dataProvider = "NumExpandData")
    public void testExpandNum(String token, String word) {
        double x = Double.parseDouble(token);
        String actual = module.expandNumber(x);
        Assert.assertEquals(actual, word);
    }

    @Test(dataProvider = "OrdinalExpandData")
    public void testExpandOrdinal(String token, String word) {
        double x = Double.parseDouble(token);
        String actual = module.expandOrdinal(x);
        Assert.assertEquals(actual, word);
    }
}
